Skip to content

fix: lane-aware attach discovery + native.attachLanePriority (#2905) - #2916

Merged
ranxianglei merged 5 commits into
masterfrom
2026-10-12_hermes-lane-isolation
Oct 12, 2026
Merged

ranxianglei merged 5 commits into
masterfrom
2026-10-12_hermes-lane-isolation

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What

#2905: dsh spawn 一个实例之后 Hermes 会尝试 attach 到 dsh 实例上,导致 hermes 工具 404。根因修复 + 泳道优先级配置。

Root cause

The hermes native plugin's discovery (hermes-plugin/__init__.py) read only the single last-writer proxy-origin file and checked only pid-liveness + manifest probe + watchdog gate — no lane, no code fingerprint, no config shape. After dsh spawned its lane proxy (last writer), hermes attached to it; dsh's MITM whitelist doesn't cover hermes's providers, so model traffic blind-tunneled, no session ever arrived under hermes's conversation id, and every /__bili/plugin/tool call 404'd with "unknown plugin conversation".

Compounding it: hermes-spawned proxies never declared a lane (BILI_LAUNCHER_LANE unset) — wildcard instances ANY lane could ride — and an older lane-less record lost to a newer one by recency, so the 8787 user-zone daemon could beat the lane's own instance ("8787 优先级第一").

Fix

  1. hermes-plugin — discovery is now the Python twin of probeLiveInstances + pickAttachable (src/launcher.ts): scans EVERY registry marker plus the proxy-origin file (registry wins id collisions), requires entry-script sha256 fingerprint, bind host / passthrough / MITM-whitelist / model-table identity, and applies the lane rules: own lane first → operator-listed foreign lanes → user zone ALWAYS last. The claude-native hooks must not attach to a lifecycle-less proxy — attach gate + self-managed fallback #1335 lifecycle gate still applies except to the user zone ([Design] 定死端口 lane(claude 48787 / zcode 48789)端口被占时的 0 配置解法 #1660 twin). Spawned proxies now declare lane: hermes, so no other lane can ride them and a second hermes session converges on the first hermes proxy.
  2. launcher.ts — new attachClass(): own lane (0) → listed foreign lanes in list order (1..n) → undeclared lanes / user zone ALWAYS last (n+1). A foreign DECLARED lane is attachable only when listed. Default [] = zero behavior change for existing TS lanes.
  3. config.ts — new key + resolver.

config surface

  • Added: native.attachLanePriority: string[] in ~/.config/billion-context/billion-context.json. File-only, NO env var (env discipline 彻底整治环境变了滥用,除非必要都走配置文件 #2030: behavior knobs are file keys resolved through the existing hierarchy).
  • Why the existing surface cannot express it: native.attachExternal is a boolean over WATCHDOG state — it cannot express ordering or per-lane opt-in; the providers table and the compress hierarchy have no notion of attach targets at all.
  • Mechanisms considered: per-lane fields (e.g. hermes.attachLanes) — rejected: attach priority is one machine-level policy shared by every lane-aware site (TS lanes + python twin), not a per-lane knob; env var — rejected per 彻底整治环境变了滥用,除非必要都走配置文件 #2030 category rules; port-pinning style keys — unrelated dimension (port ≠ identity).
  • Compat/migration: additive. Absent → [] → exactly today's behavior (own lane → user zone → spawn). Nothing to migrate.

Behavior changes (old → new)

  1. hermes no longer rides foreign-lane instances (was: blind last-writer attach — the reported bug). Now refused with an operator-visible warning; spawn fallback as before.
  2. hermes-spawned proxies now declare lane: hermes (were wildcard). Other lanes can no longer ride them; a second hermes session converges on the first hermes proxy instead of possibly preferring 8787 by recency.
  3. hermes discovery scans the full instance registry (was: single last-writer file).
  4. User-zone daemons (manual bili start / 8787) become attachable as LAST-resort fallback even when unarmed — mirrors the TS lanes' [Design] 定死端口 lane(claude 48787 / zcode 48789)端口被占时的 0 配置解法 #1660 semantics (the python twin previously refused them unless native.attachExternal=true).
  5. New config native.attachLanePriority — default [] = no cross-lane attach; own lane always first; 8787 always last. Example: "native": {"attachLanePriority": ["dsh"]}.

Notes

Closes #2905

ework-agent added 3 commits October 12, 2026 18:25
A dsh-spawned instance was the last writer of the single proxy-origin
file, so a hermes native session attached to it blindly (the Python
plugin checked neither lane nor code fingerprint nor config shape). Its
MITM whitelist does not cover hermes's providers, so model traffic
blind-tunneled, no session ever arrived under hermes's conversation id,
and every compression tool call 404'd.

- hermes-plugin: discovery now mirrors probeLiveInstances + pickAttachable
  (src/launcher.ts) — scans every registry marker plus the proxy-origin
  file (registry wins id collisions), requires entry-script fingerprint,
  bind host/passthrough/MITM-whitelist/model-table identity, and applies
  the lane rules: own lane first, operator-listed foreign lanes next,
  user zone (manual bili start, the 8787 global) ALWAYS last. The #1335
  lifecycle gate keeps applying except to the user zone (#1660 twin).
  Spawned proxies now declare lane: hermes (BILI_LAUNCHER_LANE) so no
  other lane can ride them.
- launcher.ts: attachClass() replaces the two-class rule with own lane ->
  listed foreign lanes (native.attachLanePriority order) -> undeclared
  lanes last; instanceCompatible admits a foreign declared lane only when
  listed. Default [] = zero behavior change for existing TS lanes.
- config.ts: native.attachLanePriority (string[], file-only, no env var
  per #2030) + resolveNativeAttachLanePriority().

Closes #2905
- hermes driver: existing discover-* fixtures now carry full identity
  fields (fingerprint/lane/host/passthrough/mitm/modelWindows); new
  scenarios: discover-foreign-lane (the reported bug — dsh instance is
  refused, not ridden), discover-user-zone (unarmed 8787-style daemon is
  a legitimate last-resort target, #1660 twin), discover-lane-first
  (own lane beats a NEWER user zone; registry scanned beyond the file),
  discover-priority-config (attachLanePriority opt-in rides a listed
  foreign lane), spawn-env (spawned proxies declare BILI_LAUNCHER_LANE).
- launcher: listed foreign lane attachable / list position beats recency
  / unlisted foreign lane stays refused with user zone last.
- config: resolveNativeAttachLanePriority normalization (trim, dedupe,
  non-array/garbage -> []).
CONFIGURATION.md en/zh (summary table + native section), README en/zh
port note, CLIENTS en/zh hermes lifecycle bullet, website config
reference. New key: native.attachLanePriority (string[], file-only,
default [] = own lane -> user zone -> spawn).
@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-12_hermes-lane-isolation (eed86e7)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.3251-pr.2916.e9f3c9c

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr2916.tgz
npm install -g package

Install instructions are refreshed on each push.

…2905)

check-coverage forbids backticks in desc_en/desc_zh (tools/gen-config-docs.mjs:118);
remove them from the native.attachLanePriority seed and take the generator's
canonical table rows instead of the hand-edited ones (docs-sync drift).
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷

收到,开始核对 #2916。

身份确认:这是带 ework-agent-pr 标记的 agent 已完成工作(分支 2026-10-12_hermes-lane-isolation,3 commits,+567/-90)。按规矩我不重做,只核代码 + CI。当前 mergeable=True,base=master。

CI 现状(红):docs-sync、docs-coverage 两个 job FAILURE;test、static-gates 因 needs 依赖被连带 SKIPPED(整个测试门禁没跑到)。其余 kernel-guard / config-surface-guard / lane-guard / lock-sync / build-artifact / codex-e2e 各腿全绿。

根因(单点缺陷级联):website/config-reference/server.yaml 新增的 native.attachLanePriority 条目里,desc_en 和 desc_zh 都用反引号包了 bili start,而 tools/gen-config-docs.mjs:118 明确禁止 desc 字段出现反引号(backtick forbidden in desc_en)。fail() 命中第一个就 process.exit(1),所以只报了 desc_en——desc_zh 也有一处,必须一起修,否则下一轮还会在那里挂。就这一个文档 lint 缺陷,把 docs→test 的整条门禁卡死了。

处置:我现在就去掉这两处反引号(纯文档 seed 改动,不动配置语义、不 bump 版本),本地跑 gen-config-docs generate+check-coverage 验证转绿后推回 PR 分支,再确认 CI 的 test/static-gates 解锁。稍后按八问体例给结构化结论。

…esynced the code fingerprint (#2905)

install_sidecar used text-mode open("w"): on Windows \n becomes \r\n on
disk, so the sha256 discovery hashes (real file bytes) never matched fp_of()
(LF constant) and every candidate was refused pre-probe — all discover-*
scenarios inert on windows-latest. Binary write makes on-disk bytes equal
the fixture hash on every platform.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷

核对完成。#2916 现已全绿(22/22 checks,0 fail),可合并。 下面是结构化结论。

先交代我的实际动作:这是带 ework-agent-pr 标记的 agent 已完成工作,我没重做、也没往分支推任何东西(我本地一度做了一个等价测试修复的提交,发现原作者已并发推了等价修复后,已丢弃,分支净变更=0)。我做的是:独立复现并定位了两处根因(拿证据),并逐条验证分支上已有的两个修复 commit 是否正确且充分。

关键背景:我接手时 CI 是红的,而且红的原因不是单一缺陷——是两个相互独立的缺陷,先后由原作者在 5558f6a 和 eed86e7c 两个 commit 修掉。我逐一核验如下。


1. 是什么问题(两个,不是一个)

  • (A) 文档 lint 违规:新增的 native.attachLanePriority seed 条目在 desc_en/desc_zh 里用了反引号包 bili start,而 tools/gen-config-docs.mjs 明令禁止 desc 字段出现反引号。它单独就 fail 了 docs-sync+docs-coverage,又因 needs 依赖把 test+static-gates 整条门禁连带 SKIPPED。
  • (B) Windows 专属测试回归:新加的 hermes lane-aware discovery 让全部六个 discover-* 子进程测试在 windows-latest 上返回 null(ubuntu 全绿)。

2. 什么原因导致的

  • (A) 反引号触发 gen-config-docs.mjs:118 硬失败;fail() 命中第一个就 process.exit(1),所以日志只报了 desc_en——但 desc_zh 同样违规,必须一起改。
  • (B) 新逻辑里 discover_instance() 用 _sha256_file(按原始字节 open("rb") 哈希)算指纹,而 _attach_reason 把「指纹不一致」作为第一道拒绝条件。测试夹具用文本模式写 proxy.js,Windows 会把 \n→\r\n;而夹具期望指纹 fp_of() 哈希的是裸 LF 字面量。于是 Windows 上两者字节不一致 → 每个候选都在最前面被拒 → discover_instance() 返回 None → 六个测试全 null。Linux 文本模式原样写 LF,所以那边绿。这个指纹检查是本 PR 新增的,故 master 一直是绿的。我用一个独立脚本证明了机制:文本模式写出的字节哈希 ≠ 期望值(bug),改成字节精确 LF 后哈希 == 期望值(修复)。

3. 影响范围与严重程度

  • (A) 纯文档/lint,无运行时影响;但卡住了合并门禁。
  • (B) 无生产/运行时影响——这是测试夹具的确定性 bug(§7.2「不许靠环境运气」),生产的指纹逻辑(哈希原始字节)本身是对的、也是想要的。只有 windows-latest 一条腿红,真实用户零影响。严重度=合并阻塞(CI 红),用户面=无。

4. 怎么修复的

  • (A) 去掉 desc_en/desc_zh 两处反引号,并重新生成 CONFIGURATION.md/CONFIGURATION.zh-CN.md 对应行(commit 5558f6a)。
  • (B) 让被哈希的 sidecar 以字节精确的 LF 写出,使其哈希在所有 OS 上都等于 fp_of()——用二进制写 .encode() 实现(commit eed86e7c),写入表达式与 fp_of() 的入参逐字节相同,匹配是构造上保证的。(我本地另验证了等价的 newline="" 方案并证明字节匹配成立。)

5. 是否有回归问题:无。两个修复都是纠正性/增量,无语义漂移:

  • 文档修复:纯内容,不动语义/阈值/时序/输出格式。
  • 测试修复:只动测试夹具的文件写模式,生产代码(src/、kernel/、hermes-plugin/__init__.py 的逻辑)一行未碰;指纹哈希语义不变。没有 fail-fast 变吞错、没有默认值/阈值/格式漂移。
  • 证据:本地 gen-config-docs generate+漂移检查+check-coverage 均 exit 0;CI 在 eed86e7c 上 22/22 全绿。

6. 是否破坏缓存:不涉及。两处改动都不触碰缓存/重试/增量游标/去重键(这里的 fingerprint 是 attach-discovery 的身份判定,不是缓存失效路径)。

7. 是否改了设计方向:不涉及。架构/边界/数据流未转向;lane-aware attach 的设计(本 lane → 列出的外部 lane → 用户区 → spawn)完整保留,且现在有跨平台通过的测试兜底。

8. 是否引入新的配置:本 PR 引入 native.attachLanePriority(string[],默认 [],仅配置文件、无 env 变量)——这是被评审的特性本身,已在 CONFIGURATION en/zh + server.yaml seed 里记录。opt-in、默认 []=零行为变化(仍是 本 lane → 用户区 → spawn)。我这次介入没有新增任何配置。


收工判定:两处缺陷均已修复并经我核验正确且充分,CI 在当前 head eed86e7c 全绿(含 ubuntu/windows × node22/24 四条 test 腿 + 全部 guard/build/codex-e2e)。可以合并——合并动作留给你(系统规则禁止 agent 合并 PR)。

@ranxianglei
ranxianglei merged commit c76650f into master Oct 12, 2026
22 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.330-master.c76650f (rolling master tag).

npm install -g billion-context@0.0.330-master.c76650f  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dsh spawn 一个实例之后 Hermes会尝试 attach到dsh实例上 导致hermes工具404

1 participant